<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var arr = [1, 2, 3];
        var obj1 = {
            name: '张三',
            age: 18
        }
        // 简单深拷贝函数
        function deepCopy(obj1) {
            // ES5精准判断数据类型
            var obj = Object.prototype.toString.call(obj1) === '[object Array]' ? [] : {} ;
            for (var key in obj1) {
                obj[key] = obj1[key];
            }
            return obj;
        }
        var obj2 = deepCopy(obj1);
        obj2.name = 'lisi'
        console.log(obj2);
        console.log(obj1);

        // 多层对象或数组 ,简单拷贝函数，只能控制最外面一层，里面的对象仍然被引用了
        var obj3 = {
            name: '王俊凯',
            age: 18,
            hoppy: {
                name1: '篮球',
                name2: '足球'
            }
        }
        var obj4 = deepCopy(obj3);
        obj4.hoppy.name1 = '羽毛球';
        console.log(obj3);
    </script>
</body>
</html>